home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1076 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: ohstpy.mps.ohio-state.edu!vancleef
  2. From: vancleef@ohstpy.mps.ohio-state.edu
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Template Class Linkage?
  5. Message-ID: <1996Jan9.004515.8691@ohstpy>
  6. Date: 9 Jan 96 00:45:15 -0500
  7. References: <4cmnjs$mk7@mimsy.cs.umd.edu> <4cq4hs$raa@news2.deltanet.com> <4crpps$7ni@mimsy.cs.umd.edu>
  8. Organization: The Ohio State University, Department of Physics
  9.  
  10. In article <4crpps$7ni@mimsy.cs.umd.edu>, gilman@cfar.umd.edu (Gil Carmel) writes:
  11. > Sergio Olivas (olivas@deltanet.com) wrote:
  12. > : >I'm just learning templates, and I'm having problems with linkage.
  13. > : >When the template class member function bodies are included in the .h file,
  14. > : >everything is fine.  But when the function bodies are in a separate .c file,
  15. > : >calls to these functions from other files give an "undefined reference to
  16. > : >function" error from the linker.  Do template class member functions have 
  17. > : >to be in the ".h" file, or is this a problem with my compiler?
  18. > : Yes, this is a known 'feature' of C++ -- As far as the language
  19. > : standard and all the compilers go. I understand an update to the C++
  20. > : language will include some way of including the template stuff into
  21. > : the .c (cpp) files, as well as provide the Standard Template library
  22. > : as part of the language.
  23. > : later,
  24. > :   sergio
  25. > Thanks.  One more question:
  26. > What happens if two different files use the same template class function?
  27. > If both need to include the function body, then it will be defined twice and
  28. > the linker will produce an error.
  29.  
  30. This works fine. I use templates all the time. Just remember
  31. that the template 'source code' must be included in
  32. the header file.
  33.  
  34. -Garrett
  35.  
  36.  
  37.  
  38. > Gil
  39. > --
  40. > |-----------------------------------------------------------|
  41. > | Gil Carmel             | gilman@wam.umd.edu        |
  42. > | Computer Science Undergraduate | gilman@cfar.umd.edu        |
  43. > | University of Maryland     |                |
  44. > | College Park, MD         |                |
  45. > |-----------------------------------------------------------|
  46. > | |                \o              | |
  47. > | |                 |\              | |
  48. > | |                / \              | |
  49.